package com.kongwg.java1;

public class Singleton {
	public static void main(String[] args) {
		Test test = Test.getTest();
		Test1 test1 = Test1.getTest();
		
		
	}
}

//饿汉式
class Test{
	private Test(){
		
	}
	
	private static Test instance = new Test();
	
	
	public static Test getTest(){
		return instance;
	}
}


//懒汉式
class Test1{
	private Test1(){
		
		
	}
	
	
	
	private static Test1 instance = null;
	
	public static Test1 getTest(){
		if(instance != null){
			instance = new Test1();
			return instance;
		}
		return instance;
	}
	
}